package com.example.dormlist.controller;


import com.alibaba.fastjson.JSONObject;
import com.example.dormlist.dorm.DormList;
import com.example.dormlist.dorm.DormListService;
import com.example.dormlist.entity.DormitoryBuilding;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpRequest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.HttpHeadersReturnValueHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@AllArgsConstructor
@RequestMapping("")
public class DormResource {

    private final DormListService dormListService;

    @GetMapping("/hello")
    public String hello() {
        return "here in dorm list";
    }

    @GetMapping("/list")
    public ResponseEntity showDormList(HttpServletRequest request) {
        List<DormList> dormData = dormListService.findAll();
        String uid = request.getSession().getAttribute("uid").toString();
        Map<String, Object> result = new HashMap<>();
        result.put("uid", uid);
        result.put("dormList", dormData);
        return new ResponseEntity(result, HttpStatus.OK);
//        Map<String, Integer> dormList = new HashMap<>();
//        dormList.put("5号楼", 200);
//        dormList.put("8号楼", 80);
//        dormList.put("9号楼", 50);
//        dormList.put("13号楼", 300);
//        dormList.put("14号楼", 100);
//        return new JSONObject().fluentPutAll(dormList);
    }


}
